#include "stdafx.h"
#define COMMON_UTIL_EXPORTS
#include "UtilService.h"
#include "MsgSpliter.h"
#include "AirlineServ.h"
#include "CusServ.h"

#pragma comment (lib, "Ws2_32.lib")

IMsgSplitter* CreateMsgSplitter() { return new CMsgSpliter; }

void DestroyMsgSplitter(IMsgSplitter* pSplitter) { delete pSplitter; }

void DeleteMsg(MSG_BASE* pMsg) { delete pMsg; }

void SendMessage(MSG_BASE* pMsg, SOCKET sock)
{
	if (NULL == pMsg) return;

	int nLft = pMsg->nMsgLen;
	const char* p = (const char*)pMsg;
	while (nLft > 0)
	{
		int nSent = send(sock, p, nLft, 0);
		if (nSent <= 0) break;

		nLft -= nSent;
		p += nSent;
	}
}

IAirlineServ* CreateAirlineService(SOCKET sock) { return new AirlineServ(sock); }

void DestroyAirlineService(IAirlineServ* pServ) { delete pServ; }

ICusServ* CreateCustomerService(SOCKET sock) { return new CusServ(sock); }

void DestroyCustomerService(ICusServ* pServ) { delete pServ; }